class CameraCanvas {
    private _canvas: HTMLCanvasElement
    private _context2d: CanvasRenderingContext2D | null
    private _camera: HTMLVideoElement | null = null

    constructor(width: number, height: number) {
        this._canvas = document.createElement('canvas')
        this._canvas.width = width
        this._canvas.height = height
        this._context2d = this._canvas.getContext('2d')
    }

    drawVideo() {
        if (!!this._camera) {
            this._context2d &&
                this._context2d.drawImage(
                    this._camera,
                    33,
                    71,
                    104,
                    124,
                    21,
                    20,
                    87,
                    104
                ) //绘制视频
        }
        requestAnimationFrame(this.drawVideo.bind(this))
    }

    setCameraVideo(element: HTMLVideoElement) {
        console.log('element =>', element)
        this._camera = element
        this.drawVideo()
    }

    get canvas() {
        return this._canvas
    }
}

export default CameraCanvas
